from langchain_core.messages import HumanMessage, SystemMessage
from langchain_openai import ChatOpenAI
# from langchain.chat_models import ChatOpenAI
# from langchain_community.chat_models import ChatOpenAI
import os

os.environ["OPENAI_API_KEY"] = "sk-f5324346ba744ef89eda093af8f307c7"
os.environ["OPENAI_API_BASE"] = "https://dashscope.aliyuncs.com/compatible-mode/v1"
# os.environ["LANGCHAIN_VERBOSE"] = "false"
# os.environ["LANGCHAIN_TRACING_V2"] = "false"  # 小写false

# 移除所有LANGCHAIN_VERBOSE相关设置（已完全废弃）
# 添加新版SDK的日志控制配置
os.environ["LANGCHAIN_API_KEY"] = "ls_..."  # 非必填，仅需关闭日志时可不填
os.environ["LANGCHAIN_TRACING_V2"] = "false"

messages = [
    SystemMessage(content="Translate the following from English into Chinese:"),
    HumanMessage(content="Welcome to LLM application development!"),
]

# model = ChatOpenAI(model="gpt-4o-mini")
model = ChatOpenAI(model="deepseek-r1")
# 同步调用
# result = model.invoke(messages)
# print(result)

# 流式返回
stream = model.stream(messages)
for response in stream:
    print(response.content, end="|")
